<?php

namespace app\common\service;

use app\common\model\mysql\AccountOperationModel;
use think\facade\Cache;
use think\facade\Cookie;

class OperaService
{
    public function __construct($opera)
    {
        if (empty($opera)) {
            return '';
        }
        $token = Cookie::get('token');
        $account = Cache::get($token);

        $request = app('request');

        $accountOpera['account_id'] = $account['id'];
        $accountOpera['account_name'] = $account['account_name'];
        $accountOpera['route'] = $request->url();
        $accountOpera['title'] = $opera['title'] ?? '操作行为';
        $accountOpera['content'] = $opera['content'];
        $accountOpera['ip'] = $request->ip();
        $accountOpera['useragent'] = $request->header('user-agent');
        $accountOpera['outcome'] = $opera['outcome'] ?? 'success';
        $accountOpera['system_id'] = config('admin.system_id');
        AccountOperationModel::addData($accountOpera);
    }
}